package com.tinytoon.hunghoaqua;

import com.tinytoon.hunghoaqua.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class GameActivity extends Activity {
	public static final int MAX_RANGE = 2000;
	public static SeekBar sb;
	public int lastProgress = 50;
	public int n = 0;
	Panel panel;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.game);

		panel = (Panel) findViewById(R.id.surface);
		sb = (SeekBar) findViewById(R.id.slider);
		sb.incrementProgressBy(1);
		sb.setMax(MAX_RANGE);
		sb.setProgress(MAX_RANGE / 2);
		sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			public void onStopTrackingTouch(SeekBar seekBar) {
				// key up
				panel.mMario.handleInput(Mario.INPUT_STAND, 0);
			}

			public void onStartTrackingTouch(SeekBar seekBar) {
			}

			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				if (progress > lastProgress) {
					panel.mMario.handleInput(Mario.INPUT_MOVE_RIGHT, progress);
				} else if (progress < lastProgress) {
					panel.mMario.handleInput(Mario.INPUT_MOVE_LEFT, progress);
				}
				lastProgress = progress;
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == GameOverActivity.RESULT_RETURN) {
			finish();
		} else if (resultCode == GameOverActivity.RESULT_PLAY_FROM_BEGIN) {
			panel.GAME_LEVEL = 1;
			panel.setMode(Panel.MODE_READY);
		} else if (resultCode == GameOverActivity.RESULT_REPLAY) {
			panel.mPlayerScore = panel.mLastPLayerScore;
			panel.setMode(Panel.MODE_READY);
		} else {// player press back button on GameOverActivity
			finish();
		}
	}

	public void onJump(View view) {
		panel.mMario.handleInput(Mario.INPUT_JUMP, 0);
	}
}